# coding:utf-8
from flask_wtf import FlaskForm
from wtforms import SelectField, StringField, TextAreaField, SubmitField, \
    PasswordField, BooleanField, HiddenField
from wtforms.validators import DataRequired, Length, Email, EqualTo, length


class UpdatePasswordForm(FlaskForm):
    password = PasswordField(u'密码',
                             validators=[DataRequired(),
                                         length(min=8, max=16),
                                         EqualTo('repassword',
                                                 message=u'两次输入密码不一致！')])
    repassword = PasswordField(u'确认密码', validators=[DataRequired()])
    submit = SubmitField('提交')


class MessageForm(FlaskForm):
    content = TextAreaField(u'留言', validators=[DataRequired(), length(min=5, max=300)])
    msg_type = SelectField(u'类型', choices=((1, '建议'), (2, '问题反馈'), (3, '其他')),
                           validators=[DataRequired()])
    submit = SubmitField('提交')

class UserProfileForm(FlaskForm):
    user_id = HiddenField(u'', validators=[DataRequired()])
    username = StringField(u'昵称', validators=[DataRequired(), length(min=3, max=16)])
    gender = SelectField(u'昵称', choices=((1, u'男'), (0, u'女')))
    submit = SubmitField('提交')

class AccessForm(FlaskForm):
    password = PasswordField(u'访问密码', validators=[DataRequired(), length(min=6, max=16)])
    submit = SubmitField('提交')


class CreateClubForm(FlaskForm):
    name = StringField(u'名称', validators=[DataRequired(), length(min=3, max=15)])
    password = PasswordField(u'访问密码', validators=[DataRequired(), length(min=6, max=16)])
    desc = TextAreaField(u'简介', validators=[DataRequired(), length(min=8, max=32)])
    submit = SubmitField('提交')

class UpdateClubForm(FlaskForm):
    club_id = HiddenField(u'', validators=[DataRequired()])
    name = StringField(u'名称', validators=[DataRequired(), length(min=3, max=15)])
    password = PasswordField(u'访问密码', validators=[length(min=6, max=16)])
    desc = TextAreaField(u'简介', validators=[DataRequired(), length(min=6, max=32)])
    submit = SubmitField('提交')

class CreatePostForm(FlaskForm):
    title = StringField(u'标题', validators=[DataRequired(), length(min=5, max=50)])
    content = TextAreaField(u'内容', validators=[length(min=6)])
    club_id = SelectField(u'俱乐部', validators=[DataRequired()])
    submit = SubmitField('提交')

class UpdatePostForm(FlaskForm):
    post_id = HiddenField(u'', validators=[DataRequired()])
    title = StringField(u'标题', validators=[DataRequired(), length(min=5, max=50)])
    content = TextAreaField(u'内容', validators=[length(min=6)])
    club_id = SelectField(u'俱乐部', validators=[DataRequired()])
    submit = SubmitField('提交')

class CommentForm(FlaskForm):
    username = StringField(u'昵称', validators=[DataRequired()])
    content = TextAreaField(u'评论',
                            validators=[length(min=1, max=400)])
    email = StringField(u'邮箱',
                        validators=[DataRequired(), Length(1, 64), Email()])
    is_appear = BooleanField('私密评论')
    submit = SubmitField('提交')


class SubmitAboutForm(FlaskForm):
    content = TextAreaField(u'文章内容', validators=[DataRequired()])


class CommentsForm(FlaskForm):
    name = StringField(u'昵称', validators=[DataRequired()])
    email = StringField(u'邮箱',
                        validators=[DataRequired(), Length(1, 64), Email()])
    content = TextAreaField(u'内容', validators=[DataRequired(), Length(1, 1024)])
    follow = StringField(validators=[DataRequired()])


class CommonForm(FlaskForm):
    types = SelectField(u'文章分类', coerce=int, validators=[DataRequired()])


class DeleteArticleForm(FlaskForm):
    articleId = StringField(validators=[DataRequired()])


class DeleteArticlesForm(FlaskForm):
    articleIds = StringField(validators=[DataRequired()])


class DeleteCommentsForm(FlaskForm):
    commentIds = StringField(validators=[DataRequired()])


class AdminCommentForm(CommentForm):
    article = StringField(validators=[DataRequired()])


class CustomXInfoForm(FlaskForm):
    title = StringField(u'博客标题', validators=[DataRequired()])
    signature = TextAreaField(u'个性签名', validators=[DataRequired()])
    navbars = SelectField(u'导航样式', coerce=int, validators=[DataRequired()])


class ChangePasswordForm(FlaskForm):
    old_password = PasswordField(u'原来密码', validators=[DataRequired()])
    password = PasswordField(u'新密码', validators=[
        DataRequired(), EqualTo('password2', message=u'两次输入密码不一致！')])
    password2 = PasswordField(u'确认新密码', validators=[DataRequired()])


class EditUserForm(FlaskForm):
    username = StringField(u'昵称', validators=[DataRequired()])
    email = StringField(u'电子邮件',
                        validators=[DataRequired(), Length(1, 64), Email()])
    password = PasswordField(u'密码确认', validators=[DataRequired()])


class LoginForm(FlaskForm):
    email = StringField(u'邮箱', validators=[DataRequired(), Length(1, 64),
                                           Email()])
    password = PasswordField(u'密码', validators=[DataRequired()])
